print "enter a number:"
n = io.read("*number")
if not n then error("invalid input",2) end

function function_error(  )
    -- body
    print("The error input !")
end
print "enter a number:"
n = assert( io.read("*number"), function_error() )

print "enter a number:"
n = assert( io.read("*number"), "invalid input" )

-- local file, msg
-- repeat
--     print "enter a file name:"
--     local name = io.read()
--     if not name then return end -- no input
--         file, msg = io.open(name, "r")
--     if not file then print(msg) end
-- until file

local status, err = pcall( function () error({code=121}) end )
print(status)
print(err.code) --> 121
local status, err = pcall(function () a = 'a'+1 end)
print(status)
print(err)

-- 没有错误
local status, err = pcall(function () a = 1+1 end)
print(status)
print(err)

function foo (str)
    if type(str) ~= "string" then
    error("string expected")
    end
end

function foo (str)
    if type(str) ~= "string" then
    error("string expected", 2)
    end
end
-- foo({x=1})
print(debug.traceback())
print( debug )